<template>
  <div>
      <el-form inline>
        <el-form-item label="订单编号：">
          <el-input  @change="search" clearable v-model="params.orderSn"></el-input>
        </el-form-item>
        <el-form-item label="产线：">
          <el-select @change="search" clearable style="width:220px" v-model="params.lineId" placeholder="请选择">
            <el-option
              v-for="(item, index) in lineList"
              :key="index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="排产时间：">
          <el-date-picker
           @change="search"
             value-format="yyyy-MM-dd"
            v-model="params.deliveryTime"
            type="date"
            placeholder="选择日期">
          </el-date-picker> 至 
          <el-date-picker
           @change="search"
           value-format="yyyy-MM-dd"
            v-model="params.updateTime"
            type="date"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="接线盒电流">
          <el-select @change="search" clearable style="width:220px" v-model="params.electric" placeholder="请选择">
            <el-option label="20A" value="20A"></el-option>
            <el-option label="25A" value="25A"></el-option>
            <el-option label="30A" value="30A"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
    <el-card style="width: 100%; margin-top: 20px" class="box-card">
      <el-table
        max-height='675px'
        v-loading="loading"
        :data="tableData"
        border
        show-summary
        class="table"
        :row-key="getRowKeys"
        ref="multipleTable"
        header-cell-class-name="table-header"
      >
        <el-table-column
          type="index"
          fixed
          :index="indexMethod"
          align="center"
          width="50"
        >
        </el-table-column>
        <el-table-column
          label="订单编号"
          fixed
          width="180"
          prop="orderSn"
          align="center"
        ></el-table-column>
        <el-table-column
          fixed
          width="100"
          label="产线名称"
          prop="lineName"
          align="center"
        ></el-table-column>
        <el-table-column
          label="尺寸"
          prop="size"
          width="180"
          align="center"
        ></el-table-column>
        <el-table-column
          label="功率"
          prop="wattage"
          align="center"
        ></el-table-column>
        <el-table-column align="center" width="280"  label="排产日期" prop="orderArragementDate">
        </el-table-column>
        <el-table-column
          label="排产量"
          width="100"
          prop="totalQuantity"
          align="center"
        ></el-table-column>
        <el-table-column label="接线盒电流" prop="electric"  width="120" align="center"></el-table-column>
        <el-table-column
          label="线长"
           width="100"
          prop="lineLength"
          align="center"
        ></el-table-column>
        <el-table-column
          label="铭牌"
           width="100"
          prop="nameplate"
          align="center"
        ></el-table-column>
        <el-table-column
          label="纸箱"
           width="100"
          prop="carton"
          align="center"
        ></el-table-column>
        <el-table-column
          label="包装方式"
          width="180"
          prop="packingMethod"
          align="center"
        ></el-table-column>
        <el-table-column
          label="其他要求"
           width="250"
          prop="remark"
          align="center"
          :show-overflow-tooltip="true"
        ></el-table-column>
      </el-table>
      <div class="pagination">
        <pagination
          v-show="pageTotal > 0"
          :total="pageTotal"
          :page-sizes="[50,100, 200, 300, 400]"
          :page.sync="params.pageNum"
          :limit.sync="params.pageSize"
          @pagination="getData00"
        />
      </div>
      <!-- 新增编辑 -->
      <el-dialog :title="title" :visible.sync="dialogVisible" width="1000px">
        <el-form
          :rules="rules"
          ref="formName"
          :model="form"
          label-width="120px"
          size="small"
          class="form-box"
        >
          <el-row>
            <el-col :span="12">
              <el-form-item label="产线：" prop="lineId">
                <el-select :disabled="title == '编辑订单'" style="width:220px" v-model="form.lineId" placeholder="请选择">
                  <el-option
                    v-for="(item, index) in lineList"
                    :key="index"
                    :label="item.name"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="业务员：" prop="salesmanId">
                <el-select
                :disabled="title == '编辑订单'"
                  style="width:220px" 
                  @change="userChange"
                  v-model="form.salesmanId"
                  placeholder="请选择"
                >
                  <el-option
                    v-for="(item, index) in userList"
                    :key="index"
                    :label="item.userName"
                    :value="item.userId"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="接单时间：" prop="receivingTime">
                <el-date-picker
                :disabled="title == '编辑订单'"
                  style="width:220px" 
                  v-model="form.receivingTime"
                  type="date"
                  format="yyyy-MM-dd"
                  placeholder="选择日期"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="发货时间：" prop="deliveryTime">
                <el-date-picker
                  style="width:220px" 
                  v-model="form.deliveryTime"
                  format="yyyy-MM-dd"
                  type="date"
                  placeholder="选择日期"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
               <el-form-item label="订单量：" prop="totalQuantity">
                <el-input-number
                :disabled="title == '编辑订单'"
                style="width:220px" 
                  controls-position="right"
                  :min="0"
                  v-model="form.totalQuantity"
                ></el-input-number
              ></el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="包装入库：">
                <el-input-number
                  style="width:220px" 
                  v-model="form.packageQuantity"
                  controls-position="right"
                  :min="0"
                ></el-input-number
              ></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="抽检合格：">
                <el-input-number
                  style="width:220px" 
                  v-model="form.qualified"
                  controls-position="right"
                  :min="0"
                ></el-input-number
              ></el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="已出货：" prop="outQuantity">
                <el-input-number
                style="width:220px" 
                  v-model="form.outQuantity"
                  controls-position="right"
                  :min="0"
                  :max="form.totalQuantity"
                ></el-input-number
              ></el-form-item>

            </el-col>

          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="纸箱：" prop="carton">
                <el-select style="width:220px"  v-model="form.carton" placeholder="请选择">
                  <el-option
                    v-for="item in list[7]"
                    :key="item.dictLabel"
                    :label="item.dictLabel"
                    :value="item.dictLabel"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="铭牌：" prop="nameplate">
                <el-select style="width:220px"  v-model="form.nameplate" placeholder="请选择">
                  <el-option
                    v-for="item in list[6]"
                    :key="item.dictLabel"
                    :label="item.dictLabel"
                    :value="item.dictLabel"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="能源标识：" prop="energyIdentification">
                <el-select
                  style="width:220px" 
                  v-model="form.energyIdentification"
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in list[5]"
                    :key="item.dictLabel"
                    :label="item.dictLabel"
                    :value="item.dictLabel"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="生产状态：" prop="productionStatus">
                <el-select :disabled="title == '编辑订单'" style="width:220px"  v-model="form.productionStatus" placeholder="请选择">
                  <el-option label="标识待投产" value="1"></el-option>
                  <el-option label="标识投产中" value="2"></el-option>
                  <el-option label="标识投产完成" value="3"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="版型：" prop="plateShape">
                <el-select :disabled="title == '编辑订单'" style="width:220px"  v-model="form.plateShape" placeholder="请选择">
                  <el-option
                    v-for="item in list[0]"
                    :key="item.dictLabel"
                    :label="item.dictLabel"
                    :value="item.dictLabel"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="尺寸：" prop="size">
                <el-select :disabled="title == '编辑订单'" style="width:220px"  v-model="form.size" placeholder="请选择">
                  <el-option
                    v-for="item in list[1]"
                    :key="item.dictLabel"
                    :label="item.dictLabel"
                    :value="item.dictLabel"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="功率：" prop="wattage">
                <el-select :disabled="title == '编辑订单'" style="width:220px"  v-model="form.wattage" placeholder="请选择">
                  <el-option
                    v-for="item in list[3]"
                    :key="item.dictLabel"
                    :label="item.dictLabel"
                    :value="item.dictLabel"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="线长：" prop="lineLength">
                <el-select :disabled="title == '编辑订单'" style="width:220px"  v-model="form.lineLength" placeholder="请选择">
                  <el-option
                    v-for="item in list[4]"
                    :key="item.dictLabel"
                    :label="item.dictLabel"
                    :value="item.dictLabel"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="类型：">
                <el-select :disabled="title == '编辑订单'" style="width:220px"  v-model="form.kind" placeholder="请选择">
                  <el-option
                    v-for="item in list[2]"
                    :key="item.dictLabel"
                    :label="item.dictLabel"
                    :value="item.dictLabel"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="包装方式：" prop="packingMethod">
                <el-input style="width:220px"  v-model="form.packingMethod"></el-input
              ></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="质量要求" prop="quality">
                <el-select style="width:220px" v-model="form.quality" placeholder="请选择">
                  <el-option label="A级" value="A级"></el-option>
                  <el-option label="A-级" value="A-级"></el-option>
                  <el-option label="P级" value="P级"></el-option>
                  <el-option label="C级" value="C级"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="边框颜色" prop="frame">
                <el-select style="width:220px" v-model="form.frame" placeholder="请选择">
                  <el-option label="银色" value="银色"></el-option>
                  <el-option label="黑色" value="黑色"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="接线盒电流" prop="frame">
                <el-select style="width:220px" v-model="form.electric" placeholder="请选择">
                  <el-option label="20A" value="20A"></el-option>
                  <el-option label="25A" value="25A"></el-option>
                  <el-option label="30A" value="30A"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="备注：">
                <el-input v-model="form.remark"></el-input
              ></el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false" size="mini"
            >取消</el-button
          >
          <el-button @click="sure()" type="primary" size="mini"
            >保存</el-button
          >
        </span>
      </el-dialog>
      <!-- 子订单查询 -->
      <el-dialog
        title="子订单查询"
        :visible.sync="openVisible"
        width="80%"
        >
      
      <el-table
        v-loading="loading"
        :data="childrenList"
        border
        class="table"
        @selection-change="handleSelectionChange"
        ref="multipleTable"
        header-cell-class-name="table-header"
      >
        <el-table-column
          label="订单编号"
          fixed
          width="220"
          prop="orderSn"
          align="center"
        ></el-table-column>
        <el-table-column
          fixed
          width="120"
          label="产线名称"
          prop="lineName"
          align="center"
        ></el-table-column>
        <el-table-column
          label="部门"
          prop="deptName"
          align="center"
        ></el-table-column>
        <el-table-column
          label="业务员"
          prop="salesmanName"
          align="center"
        ></el-table-column>
        <el-table-column
          label="版型"
          prop="plateShape"
          align="center"
        ></el-table-column>
        <el-table-column
          label="尺寸"
          prop="size"
          align="center"
        ></el-table-column>
        <el-table-column
          label="功率"
          prop="wattage"
          align="center"
        ></el-table-column>
        <el-table-column
          label="订单量"
          prop="totalQuantity"
          align="center"
        ></el-table-column>
        <el-table-column
          label="生产状态"
          prop="productionStatus"
          width="180"
          :formatter="
            (row, column) =>
              row.productionStatus == '1'
                ? '标识待投产'
                : row.productionStatus == '2'
                ? '标识投产中'
                : row.productionStatus == '3'
                ? '标识投产完成'
                : '-'
          "
          align="center"
        ></el-table-column>
        <el-table-column
          label="接单时间"
          width="120"
          prop="receivingTime"
          align="center"
        ></el-table-column>
        <el-table-column
          label="投产时间"
          width="120"
          prop="plateShape"
          align="center"
        ></el-table-column>
        <el-table-column
          label="已投产"
          prop="operationQuantity"
          align="center"
        ></el-table-column>
        <el-table-column
          label="待投产"
          :formatter="
            (row, column) => row.totalQuantity - row.operationQuantity
          "
          align="center"
        ></el-table-column>
        <el-table-column
          label="包装入库"
          prop="packageQuantity"
          align="center"
        ></el-table-column>
        <el-table-column
          label="抽奖合格"
          prop="qualified"
          align="center"
        ></el-table-column>
        <el-table-column
          label="发货时间"
          width="120"
          prop="deliveryTime"
          align="center"
        ></el-table-column>
        <el-table-column
          label="已出货"
          prop="outQuantity"
          align="center"
        ></el-table-column>
        <el-table-column
          label="未出货"
          :formatter="(row, column) => row.totalQuantity - row.outQuantity"
          align="center"
        ></el-table-column>
        <el-table-column
          label="线长"
          prop="lineLength"
          align="center"
        ></el-table-column>
        <el-table-column
          label="能源标识"
          prop="energyIdentification"
          align="center"
        ></el-table-column>
        <el-table-column
          label="铭牌"
          prop="nameplate"
          align="center"
        ></el-table-column>
        <el-table-column
          label="纸箱"
          prop="carton"
          align="center"
        ></el-table-column>
        <el-table-column
          label="包装方式"
          prop="packingMethod"
          align="center"
        ></el-table-column>
        <el-table-column
          label="其他要求"
          prop="remark"
          align="center"
        ></el-table-column>
      </el-table>
        <span slot="footer" class="dialog-footer">
          <el-button @click="openVisible = false">关闭</el-button>
        </span>
      </el-dialog>
      <!-- 停产 -->
      <el-dialog
        title="提示"
        :visible.sync="delcause "
        width="40%"
        >
        <el-form>
           <el-form-item label="停产原因(停产后不可恢复):">
             <el-input v-model="cause"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button size="mini" @click="delcause = false">取 消</el-button>
          <el-button size="mini" type="primary" @click="okcause">确 定</el-button>
        </span>
      </el-dialog>
       <!-- 拆单 -->
      <el-dialog
        title="拆单"
        :visible.sync="delsplit"
        width="30%"
        >
          <h2>当前总订单量：<span>{{chaiNumber}}</span></h2>
          <el-button size="mini" type='warning' @click='goadd' style="margin-bottom:15px">增加</el-button><span style="color:red;font-size:12px">（* 拆后数量相加等于总订单量）</span>
          <el-form label-width="50px" class="demo-form-inline" :inline="true">
            <el-form-item :label="'第'+(index + 1)+'单'" v-for="(item,index) in number" :key="index">
              <el-input-number controls-position="right" style='width:400px' v-model='item.number'> </el-input-number> <el-button size='mini' type="danger" @click="goshao(index)">删除</el-button>
            </el-form-item>
          </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button size="mini" @click="delsplit = false">取 消</el-button>
          <el-button size="mini" type="primary" @click="oksplit">确 定</el-button>
        </span>
      </el-dialog>
      <el-dialog :visible.sync="rulesVisDia" width="60%" title="排班计划">
          <el-table border max-height="450px" :data="rulesData">
              <el-table-column  label="订单编号" prop="orderSn" align="center"></el-table-column>
              <el-table-column  label="线名" prop="lineName" align="center"></el-table-column>
              <el-table-column  label="部门" prop="deptName" align="center"></el-table-column>
              <el-table-column  label="业务员" prop="salesmanName" align="center"></el-table-column>
              <el-table-column  label="排产日期" prop="updateTime" align="center"></el-table-column>
              <el-table-column  label="未出货" prop="totalQuantity" align="center"></el-table-column>
              <el-table-column  label="班次" :formatter="(row,column) => row.shift == 1?'早班':row.shift == 2?'午班':row.shift == 3?'晚班':''" prop="shift" align="center"></el-table-column>
              <el-table-column  label="班次产能" prop="yield" align="center"></el-table-column>
            </el-table>
            <span slot="footer">
              <el-button @click="rulesVisDia = false" size="mini"
                >关闭</el-button
              >
            </span>
      </el-dialog>
      <el-dialog :visible.sync="rulesVis" width="70%" title="选择排产">
        <el-form>
          <el-form-item label="排产日期">
             <el-date-picker :picker-options="pickerOptions" @change="dateChange" value-format="yyyy-MM-dd" v-model="rulesForm.updateTime" type="date" placeholder="选择日期"></el-date-picker>
          </el-form-item>
          <div v-if="rulesData.length != 0">
            <h2>当前日期下的排产计划</h2>
            <span style="font-size:10px;color:red">(*按班次插单时为插入当前班次。)</span>
            <el-table border max-height="450px" :data="rulesData">
              <el-table-column  label="订单编号" prop="orderSn" align="center"></el-table-column>
              <el-table-column  label="线名" prop="lineName" align="center"></el-table-column>
              <el-table-column  label="部门" prop="deptName" align="center"></el-table-column>
              <el-table-column  label="业务员" prop="salesmanName" align="center"></el-table-column>
              <el-table-column  label="排产日期" prop="updateTime" align="center"></el-table-column>
              <el-table-column  label="未出货" prop="totalQuantity" align="center"></el-table-column>
              <el-table-column  label="班次" :formatter="(row,column) => row.shift == 1?'早班':row.shift == 2?'午班':row.shift == 3?'晚班':''" prop="shift" align="center"></el-table-column>
              <el-table-column  label="班次产能" prop="yield" align="center"></el-table-column>
              <el-table-column
                label="操作"
                align="center"
                fixed="right"
              >
                <template slot-scope="scope">
                  <el-button type="warning" size="mini" @click="insert(scope.row)">当前班次插单</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="rulesVis = false" size="mini"
            >关闭</el-button
          >
          <!-- <el-button @click="sureRules()" type="primary" size="mini"
            >按照日期插单</el-button
          > -->
        </span>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import { getData, getLine, addData, putData, getUser,getMerge,getcause,getsplit,ruSure,getRules} from "@/api/lineOrder";
import ItemVue from '../../../layout/components/Sidebar/Item.vue';
import { stringify } from 'querystring';
var time;
export default {
  data() {
    return {
      pickerOptions: {
        disabledDate(v) {
          return v.getTime() > Date.parse(time);
          // return v.getTime() > Date.parse(time) - 86400000;
        }
      },
      cause:'',
      delcause:false,
      visRules:false,
      delsplit:false,
      number:[],
      causeId:'',
      chaiId:'',
      childrenList:[],
      pageTotal: 0,
      rulesVis:false,
      openVisible:false,
      multipleSelection: [],
      params: {
        pageNum: 1,
        pageSize: 50,
        order_sn:'',
        lineId:'',
        salesmanId:'',
        orderStatus:1
      },
      tableData: [],
      lineList: [],
      loading: false,
      title: "",
      dialogVisible: false,
      rules: {
        totalQuantity: [
          { required: true, message: "请输入订单量", trigger: "blur" },
        ],
        outQuantity:[
          {required:true,message:'请输入已出货' ,trigger:'blur'}
        ],
        packageQuantity:[
          {required:true,message:'请输入包装入库' ,trigger:'blur'}
        ],
        qualified:[
          {required:true,message:'请输入抽奖合格' ,trigger:'blur'}
        ],
        operationQuantity:[
          {required:true,message:'请输入已投产' ,trigger:'blur'}
        ],
        productionStatus:[
           {required:true,message:'请输入生产状态' ,trigger:'blur'}
        ],
        plateShape:[
          {required:true,message:'请输入版型' ,trigger:'blur'}
        ],
        size:[
          {required:true,message:'请输入尺寸' ,trigger:'blur'}
        ],
        wattage:[
          {required:true,message:'请输入功率' ,trigger:'blur'}
        ],
        lineLength:[
          {required:true,message:'请输入线长' ,trigger:'blur'}
        ],
        energyIdentification:[
          {required:true,message:'请输入能源标识' ,trigger:'blur'}
        ],
        nameplate:[
          {required:true,message:'请输入铭牌' ,trigger:'blur'}
        ],
        carton:[
          {required:true,message:'请输入纸箱' ,trigger:'blur'}
        ],
        packingMethod:[
          {required:true,message:'请输入包装方式' ,trigger:'blur'}
        ],
        receivingTime:[
          {required:true,message:'请输入接单时间' ,trigger:'blur'}
        ],
        deliveryTime:[
          {required:true,message:'请输入发货时间' ,trigger:'blur'}
        ],
        lineId:[
           {required:true,message:'请输入产线' ,trigger:'blur'}
        ],
        remark:[
          {required:true,message:'请输入备注' ,trigger:'blur'}
        ],
        salesmanId:[
          {required:true,message:'请输入业务员' ,trigger:'blur'}
        ],
        quality:[
          {required:true,message:'请选择质量要求' ,trigger:'blur'}
        ]
      },
      rulesForm:{
        updateTime:'',
        orderSn:'',
        lineId:'',
        insertOrderSn:'',
        shift:''
      },
      chaiNumber:0,
      text: [
        "sys_shape",
        "sys_size",
        "sys_type",
        "sys_wat",
        "line_length",
        "sys_ener",
        "namePlate",
        "carton",
      ],
      list: [],
      rulesData:[],
      userList: [],
      rulesVisDia:false,
      form: {
        id: "",
        name: "",
        remark: "",
      },
    };
  },
  created() {
    for (let i = 0; i < this.text.length; i++) {
      this.getDicts(this.text[i]).then((response) => {
        this.list[i] = response.data;
      });
    }
    //获取当前时间
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    if (month < 10) {
        month = "0" + month;
    }
    if (day < 10) {
        day = "0" + day;
    }
    var nowDate = year + "-" + month + "-" + day;
    var newDate = Date.parse(nowDate)
    var now = new Date(newDate + 2592000000); 
    this.getMyDate(now)
    // this.params.receivingTime = getMoth(newDate + 2592000000)
    this.params.deliveryTime = nowDate
    this.getLine();
    // this.getUser();
    this.getData00();
  },
  methods: {
    getMyDate(str){  
        var oDate = new Date(str)
        var oYear = oDate.getFullYear()
        var oMonth = oDate.getMonth()+1
        var oDay = oDate.getDate()
        var oTime = oYear +'-'+ this.getzf(oMonth) +'-'+ this.getzf(oDay) //最后拼接时间  
        this.params.updateTime  = oTime
    },
    //补0操作  
      getzf(num){  
        if(parseInt(num) < 10){  
            num = '0'+num;  
        }  
        return num;  
    },
    search() {
      this.getData00()
    },
    insert(row){
      this.rulesForm.shift = row.shift
      this.rulesForm.insertOrderSn = row.orderSn
      this.rulesForm.lineId = row.lineId
      this.rulesForm.arragementId = row.id
        this.$confirm('是否确认从此班次插单', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          ruSure(this.rulesForm).then(res => {
            if(res.code == 200){
              this.$message.success('修改成功')
              this.rulesVis = false
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });          
        });
    },
    dateChange() {
      getRules({updateTime:this.rulesForm.updateTime}).then(res => {
        if(res.code == 200){
          this.rulesData = res.rows
        }
      })
    },
    sureRules() {
      if(this.rulesForm.updateTime == ''){
        this.$message.error('请先填写日期')
      }else {
        this.$confirm('是否确认插单', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          ruSure(this.rulesForm).then(res => {
            if(res.code == 200){
              this.$message.success('修改成功')
              this.rulesVis = false
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });          
        });
      }
    },
    getRuliesOrder(row) {
      getRules({orderSn:row.orderSn}).then(res => {
        if(res.code == 200){
          this.rulesData = res.rows;
          this.rulesVisDia = true;
        }
      })
    },
    getRuliesDia(row) {
      this.rulesForm = {
        orderSn:row.orderSn,
        lineId:row.lineId,
        updateTime:'',
        // orderArragementDate:row.orderArragementDate
      }
      time = row.updateTime
      this.pickerOptions = {
        disabledDate(v) {
          return v.getTime() > Date.parse(time);
          // return v.getTime() > Date.parse(time) - 86400000;
        }
      },
      this.rulesData = []
      this.rulesVis = true
    },
    getRowKeys(row) {
      return row.id
    },
    // 拆单
    getsplit(row){
      this.chaiId = row.id
      this.number = []
      this.chaiNumber = row.totalQuantity
      this.delsplit = true
    },
    goadd(){
      this.number.push({
        number:[]
      })
    },
    goshao(e){
      this.number.splice(e,1)
    },
    oksplit(){
      let number = []
      let a = 0
      for(let i in this.number){
        a += Number(this.number[i].number)
      }
      if(a == this.chaiNumber){
        number = number.join(',')
  
        let data = {
          id:this.chaiId,
          number:number
        }
        getsplit(data).then(res=>{
          if(res.code == 200){
            this.$message.success('拆单成功');
            this.delsplit = false
            this.getData00();
          }
        })
      }else {
        this.$message.error('拆单数量相加要等于订单量哦')
      }
    },
    // 停产
    del(row){
      this.delcause = true
      this.causeId = row.id
    },
    okcause(){
      if(this.cause == ''){
        this.$message.error('停产原因不能为空哦！')
      }else{
        let data = {
          id:this.causeId,
          cause:this.cause
        }
         getcause(data).then(res => {
          if(res.code == 200){
            this.$message.success("操作成功");
            this.delcause = false
            this.getData00();
          }
        })
      }
    },
    // 子订单查询
    getchaxun(row){
      this.childrenList = row.childrenList
      this.openVisible = true
    },
    // openVisible(){

    // },
    // 合并订单
    mergeSure() {
      let data ={
       id:this.multipleSelection.map(item => item.id),
       order:this.form
      }
      getMerge(data).then(res => {
        if(res.code == 200){
          this.$message.success("操作成功");
          this.$refs.multipleTable.clearSelection();
          this.getData00();
        }
      })
    },
    merge() {
      let show = true
      for(let i=0;i<this.multipleSelection.length - 1;i++){
        if(this.multipleSelection[i].plateShape != this.multipleSelection[i+1].plateShape){
          show = false
        } 
        if(this.multipleSelection[i].lineId != this.multipleSelection[i+1].lineId){
          show = false
        } 
        if(this.multipleSelection[i].energyIdentification != this.multipleSelection[i+1].energyIdentification){
          show = false
        } 
        if(this.multipleSelection[i].productionStatus != this.multipleSelection[i+1].productionStatus){
          show = false
        } 
        if(this.multipleSelection[i].carton != this.multipleSelection[i+1].carton){
          show = false
        } 
        if(this.multipleSelection[i].nameplate != this.multipleSelection[i+1].nameplate){
          show = false
        } 
        if(this.multipleSelection[i].plateShape != this.multipleSelection[i+1].plateShape){
          show = false
        } 
        if(this.multipleSelection[i].size != this.multipleSelection[i+1].size){
          show = false
        } 
        if(this.multipleSelection[i].wattage != this.multipleSelection[i+1].wattage){
          show = false
        } 
        if(this.multipleSelection[i].lineLength != this.multipleSelection[i+1].lineLength){
          show = false
        } 
      }
      if(show){
        this.title = '合并订单'
        this.form = JSON.parse(JSON.stringify(this.multipleSelection[0]))
        this.form.totalQuantity = 0
        for(let i= 0;i<this.multipleSelection.length;i++ ){
          this.form.totalQuantity += this.multipleSelection[i].totalQuantity
        }
        this.dialogVisible = true
      }else{
        this.$message.error('不同类型组件订单不能合并！')
      }
      console.log(show)
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
      
    },
    indexMethod(index) {
      return (this.params.pageNum - 1) * this.params.pageSize + 1 + index;
    },
    userChange(event) {
      let obj = {};
      obj = this.userList.find((item) => {
        if (item.userId === event) {
          this.form.deptId = item.deptId;
        }
      });
    },
    getLine() {
      getLine().then((res) => {
        if (res.code == 200) {
          this.lineList = res.rows;
        }
      });
    },
    add() {
      this.title = "新增订单";
      this.form = {
        name: "",
        remark: "",
        qualified:0,
        packageQuantity:0
      };
      this.dialogVisible = true;
      this.$refs.formName.resetFields();
    },
    handleEdit(row) {
      this.title = "编辑订单";
      this.form = row;
      this.dialogVisible = true;
    },
    getUser() {
      getUser().then((res) => {
        if (res.code == 200) {
          this.userList = res.rows;
        }
      });
    },
    sure() {
      this.$refs["formName"].validate((valid) => {
        if (valid) {
          if (this.title == "新增订单") {
            addData(this.form).then((res) => {
              if (res.code == 200) {
                this.$message.success("新增成功");
                this.getData00();
                this.dialogVisible = false;
              }
            });
          } else if (this.title == "编辑订单") {
            putData(this.form).then((res) => {
              if (res.code == 200) {
                this.$message.success("编辑成功");
                this.getData00();
                this.dialogVisible = false;
              }
            });
          }else if(this.title == '合并订单'){
            this.mergeSure()
            this.dialogVisible = false;
             this.getData00();
          }
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    getData00() {
      this.loading = true;
      getData(this.params).then((res) => {
          if (res.code == 200) {
            this.tableData = res.rows;
            this.pageTotal = res.total;
            this.loading = false;
          }
        })
        .catch(() => {});
    },
  },
};
</script>

<style>
.text {
  font-size: 14px;
}

.item {
  padding: 18px 0;
}

.box-card {
  width: 480px;
}
</style>